﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace WebApplication6
{
    public partial class gouwuche2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request["id"];
            string action = Request["action"];
            if (action=="jia")
            {
                DataTable dt = SQLHelper.ExecuteDataTable("select * from t_gouwuche where id="+id);

                double jiage = 0;
                int num = 0;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow row = dt.Rows[i];
                    jiage = Convert.ToDouble(row["jiage"]);
                    num = Convert.ToInt32(row["num"]);

                }

                num = num + 1;
                double zongjia = num * jiage;

                string sql = " update t_gouwuche set num=" + num + " , zongjia="+zongjia+" where id="+id;

                SQLHelper.ExecuteNonQuery(sql);
                Response.Write("<script language=javascript>alert('操作成功');window.location.href='gouwuchelist.aspx';</script>");
                return;
            }
            else if (action == "jian")
            {
                DataTable dt = SQLHelper.ExecuteDataTable("select * from t_gouwuche where id=" + id);

                double jiage = 0;
                int num = 0;

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow row = dt.Rows[i];
                    jiage = Convert.ToDouble(row["jiage"]);
                    num = Convert.ToInt32(row["num"]);

                }

                if (num == 1) {
                    Response.Write("<script language=javascript>alert('操作失败，该商品数量为一，不能在减少');window.location.href='gouwuchelist.aspx';</script>");
                    return;
                }

                num = num - 1;
                double zongjia = num * jiage;

                string sql = " update t_gouwuche set num=" + num + " , zongjia=" + zongjia + " where id=" + id;

                SQLHelper.ExecuteNonQuery(sql);
                Response.Write("<script language=javascript>alert('操作成功');window.location.href='gouwuchelist.aspx';</script>");
                return;
            }
            else if (action == "del")
            {
                

                string sql = " delete from  t_gouwuche  where id=" + id;

                SQLHelper.ExecuteNonQuery(sql);
                Response.Write("<script language=javascript>alert('操作成功');window.location.href='gouwuchelist.aspx';</script>");
                return;
            }
            
        }
    }
}
